package com.listview.ulti;

import java.io.File;
import java.util.List;

import com.example.project_out_in.Fragment_Resport;
import com.example.project_out_in.R;
import com.example.project_out_in.RegisterActivity;
import com.example.project_out_in.Register_CustomerActivity;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Environment;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class MyStringPairAdapter extends BaseAdapter {
    private Fragment activity;
    private List<MyStringPair> stringPairList;
    

    public MyStringPairAdapter(Fragment_Resport fragment_Resport, List<MyStringPair> stringPairList) {
        super();
        this.activity = fragment_Resport;
        this.stringPairList = stringPairList;
    }

   

	public MyStringPairAdapter(
			Register_CustomerActivity register_CustomerActivity,
			List<MyStringPair> myStringPairList) {
		// TODO Auto-generated constructor stub
	}



	public MyStringPairAdapter(RegisterActivity registerActivity,
			List<MyStringPair> myStringPairList) {
		// TODO Auto-generated constructor stub
	}



	@Override
    public int getCount() {
        return stringPairList.size();
    }

    @Override
    public Object getItem(int position) {
        return stringPairList.get(position);
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        
        if (convertView == null) {
            LayoutInflater inflater = activity.getLayoutInflater(null);
            convertView = inflater.inflate(R.layout.list_row, null);
        }
        TextView col1 = (TextView) convertView.findViewById(R.id.title);
        TextView col2 = (TextView) convertView.findViewById(R.id.artist);
        TextView col3 = (TextView) convertView.findViewById(R.id.duration);
        TextView col4 = (TextView) convertView.findViewById(R.id.duration1);
        TextView col5 = (TextView) convertView.findViewById(R.id.artist1);
        ImageView col6 = (ImageView) convertView.findViewById(R.id.list_image);
        //TextView col4 = (TextView) convertView.findViewById(R.id.column4);
        col1.setText(stringPairList.get(position).getColumnOne());
        col2.setText(stringPairList.get(position).getColumnTwo());
        col3.setText(stringPairList.get(position).getColumn3());
        col4.setText(stringPairList.get(position).getColumn4());
        col5.setText(stringPairList.get(position).getColumn5());
        //Log.d("ten bao ve", stringPairList.get(position).getColumn4());
        //Log.d("ten full name", stringPairList.get(position).getColumn5());
        //Log.d("ten hinh", stringPairList.get(position).getColumn6());
        File imgFile = new File(Environment.getExternalStorageDirectory()+"/Building_Msmart/"+stringPairList.get(position).getColumn6());
        if(imgFile.exists()){

            Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());

            //ImageView myImage = (ImageView) findViewById(R.id.imageviewTest);
            col6.setImageBitmap(myBitmap);

        }
        
        //col6.setImageURI(uri);
        //col4.setText(stringPairList.get(position).getColumn4());
        return convertView;
    }
}
